﻿using Furion.DatabaseAccessor;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Dilon.Core
{
    /// <summary>
    /// 用户表
    /// </summary>
    [SugarTable("sys_user", "用户表")]
    public class SysUser : DEntityBase
    {
        /// <summary>
        /// 账号
        /// </summary>
        [SugarColumn(ColumnDescription="账号", Length = 32, IsNullable = true)]
        [Required, MaxLength(32)]
        public string Account { get; set; }

        /// <summary>
        /// 密码（采用MD5加密）
        /// </summary>
        [SugarColumn(ColumnDescription="密码", IsNullable = true)]
        [Required]
        public string Password { get; set; }

        /// <summary>
        /// 昵称
        /// </summary>
        [SugarColumn(ColumnDescription="昵称", Length = 32, IsNullable = true)]
        [MaxLength(32)]
        public string NickName { get; set; }

        /// <summary>
        /// 姓名
        /// </summary>
        [SugarColumn(ColumnDescription="姓名", Length = 32, IsNullable = true)]
        [MaxLength(32)]
        public string Name { get; set; }

        /// <summary>
        /// 头像
        /// </summary>
        [SugarColumn(ColumnDescription="头像", IsNullable = true)]
        public string Avatar { get; set; }

        /// <summary>
        /// 生日
        /// </summary>
        [SugarColumn(ColumnDescription="生日", IsNullable = true)]
        public DateTimeOffset Birthday { get; set; }

        /// <summary>
        /// 性别-男_1、女_2
        /// </summary>
        [SugarColumn(ColumnDescription="性别-男_1、女_2")]
        public Gender Sex { get; set; }

        /// <summary>
        /// 邮箱
        /// </summary>
        [SugarColumn(ColumnDescription="邮箱", Length = 64, IsNullable = true)]
        [MaxLength(64)]
        public string Email { get; set; }

        /// <summary>
        /// 手机
        /// </summary>
        [SugarColumn(ColumnDescription="手机", Length = 32, IsNullable = true)]
        [MaxLength(32)]
        public string Phone { get; set; }

        /// <summary>
        /// 电话
        /// </summary>
        [SugarColumn(ColumnDescription="电话", Length = 32, IsNullable = true)]
        [MaxLength(32)]
        public string Tel { get; set; }

        /// <summary>
        /// 最后登录IP
        /// </summary>
        [SugarColumn(ColumnDescription="最后登录IP",Length =32, IsNullable = true)]
        [MaxLength(32)]
        public string LastLoginIp { get; set; }

        /// <summary>
        /// 最后登录时间
        /// </summary>
        [SugarColumn(ColumnDescription="最后登录时间", IsNullable = true)]
        public DateTimeOffset LastLoginTime { get; set; }

        /// <summary>
        /// 管理员类型-超级管理员_1、非管理员_2
        /// </summary>
        [SugarColumn(ColumnDescription="管理员类型-超级管理员_1、非管理员_2")]
        public AdminType AdminType { get; set; }

        /// <summary>
        /// 状态-正常_0、停用_1、删除_2
        /// </summary>
        [SugarColumn(ColumnDescription="状态-正常_0、停用_1、删除_2")]
        public CommonStatus Status { get; set; } = CommonStatus.ENABLE;

        /// <summary>
        /// 多对多（角色）
        /// </summary>
        [SqlSugar.SugarColumn(IsIgnore = true)]
        public ICollection<SysRole> SysRoles { get; set; }

        /// <summary>
        /// 多对多中间表（用户-角色）
        /// </summary>
        [SqlSugar.SugarColumn(IsIgnore = true)]
        public List<SysUserRole> SysUserRoles { get; set; }

        /// <summary>
        /// 多对多（机构）
        /// </summary>
        [SqlSugar.SugarColumn(IsIgnore = true)]
        public ICollection<SysOrg> SysOrgs { get; set; }

        /// <summary>
        /// 多对多中间表（用户-机构 数据范围）
        /// </summary>
        [SqlSugar.SugarColumn(IsIgnore = true)]
        public List<SysUserDataScope> SysUserDataScopes { get; set; }

    }
}
